package com.jie.deletefile.animtor;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

/**
 * Created by Administrator on 2016/12/5.
 */
public class Animotor {

    private ImageView iv;
    private ObjectAnimator a1;


    public Animotor(ImageView iv) {
        this.iv = iv;
    }

    public void startAnimotor() {

        int[] location = new int[2];
        iv.getLocationOnScreen(location);
        int x = location[0];
        int y = location[1];
        a1 = new ObjectAnimator().ofFloat(iv,"rotation",-60, 60,-60);
        iv.setPivotX(x);
        iv.setPivotY(y);
        a1.setRepeatMode(60000);
        a1.setDuration(3000);
        a1.setInterpolator(new LinearInterpolator());
        a1.setRepeatCount(ValueAnimator.INFINITE);
        a1.start();
    }

    public void stopAnimotor() {
        if (a1 != null) {
            a1.cancel();
        }
    }

}
